import { reqCategoryList, reqBannerList, reqFloorList } from '@/api'
import { CATEGORY_LIST, BANNER_LIST, FLOOR_LIST } from '@/store/mutation-types'

export default {
  namespaced: true,
  state: {
    categoryList: [],
    bannerList: [],
    floorList: [],
  },
  actions: {
    //发请求获取三级列表数据
    async getCategoryList({ commit }) {
      const res = await reqCategoryList()
      if (res.code == 200) {
        commit(CATEGORY_LIST, res.data)
      } else {
        console.log('Home组件仓库获取CategoryList失败')
      }
    },
    //发请求获取轮播图数据
    async getBannerList({ commit }) {
      const res = await reqBannerList()
      if (res.code == 200) {
        commit(BANNER_LIST, res.data)
      } else {
        console.log('Home组件仓库获取BannerList失败')
      }
    },
    //发请求获取floor数据
    async getFloorList({ commit }) {
      const res = await reqFloorList()
      if (res.code == 200) {
        commit(FLOOR_LIST, res.data)
      } else {
        console.log('Home组件仓库获取FloorList失败')
      }
    }

  },
  mutations: {
    [CATEGORY_LIST]: (context, data) => context.categoryList = data,
    [BANNER_LIST]: (context, data) => context.bannerList = data,
    [FLOOR_LIST]: (context, data) => context.floorList = data
  },

}